				<div class="col-md-7">

			    <?php
			    $pageId = isset($_GET['pageid']) ? cleanValue($_GET['pageid']) : '';
			    $filterPage = '';
			    if($pageId != ''){
			    	$filterPage = " AND pa.fb_page_id= '$pageId' ";
			    }
			    $offset = ($page - 1) * PAGING_LIMIT;

			    $sqlPost = "SELECT SQL_CALC_FOUND_ROWS p.*,pa.fb_page_id,pp.created_at, pa.page_name FROM page_post pp JOIN pages pa ON(pp.page_id=pa.page_id) JOIN posts p ON(pp.post_id=p.id) WHERE pp.user_id=" . $userId . " {$filterPage} ORDER BY pp.post_id DESC LIMIT $offset, " . PAGING_LIMIT;
			    $rsPost = mysql_query($sqlPost);
			    if(mysql_num_rows($rsPost) > 0){
			    	$rsTotal = mysql_query("SELECT FOUND_ROWS() AS total");
			    	$total = mysql_fetch_array($rsTotal);
			    	$pages = new Paginator;
			    	$pages->items_total = $total['total'];
			    	$pages->mid_range = 3;
			    	$pages->num_pages = ceil($total['total']/PAGING_LIMIT);
			    	$pages->items_per_page = PAGING_LIMIT;
			    	$pages->querystring = true;
			    	$pages->default_ipp = PAGING_LIMIT;
			    	if($pageId != ''){
			    		$pages->strQuery = '&pageid=' . $pageId;
			    	}
			    	$pages->paginate();
				?>
					<div class="panel panel-default">
					  <!-- Default panel contents -->
					  <div class="panel-heading">
					  	<h4>
					  		List post
						  	<form class="form-inline pull-right" role="form" style="max-width:250px;">
								<div class="form-group inline-form">
									<select class="form-control input-sm" id="filter-page">
										<option value="">Filter by Page name</option>
										<?php echo getOptPage(); ?>
									</select>
								</div>
							</form>
					  	</h4>
					  </div>
					  <!-- Table -->
					  <table class="table table-hover tbl-list-post">
					    <tr>
					    	<th>Page name</th>
					    	<th>URL</th>
					    	<th>Name</th>
					    	<th>Message</th>
					    	<th style="width: 145px;">Publish</th>
					    </tr>
					    <?php
					    	$strBulk = '';
					    	$arrPublished = array();
					    	while($rowPost = mysql_fetch_array($rsPost)){
					    		if($rowPost['post_from_bulk'] == 1){
					    			$strBulk = '<span class="glyphicon glyphicon-flash" title="Post using bulk feature" style="font-size: 13px;"> </span> ';
					    		}
					    		else{
					    			$strBulk = '';
					    		}
								$trimUrl = trimInTheMiddle($rowPost['post_url']);

								$publishTime = strtotime($rowPost['post_publish_time']);
								if(time() - $publishTime > 0){
									$glyphicon = '<a title="View on Facebook" href="https://facebook.com/'.$rowPost['post_fb_id'].'" target="_blank"><span class="glyphicon glyphicon-ok-circle" style="font-size: 13px;"> </span></a>';
									$cls = '';
									array_push($arrPublished, str_replace("'", '%27', $rowPost['post_url']));
								}
								else{
									$glyphicon = '<a title="View schedule on Facebook" href="https://facebook.com/'.$rowPost['fb_page_id'].'?sk=allactivity" target="_blank"><span class="glyphicon glyphicon-time" style="font-size: 13px;"> </span></a>';
									$cls = 'bg-warning';
								}
					   	?>
					    <tr class="<?php echo $cls ?>">
					    	<td><a href="https://facebook.com/<?php echo $rowPost['fb_page_id'] ?>" target="_blank"><?php echo $strBulk . $rowPost['page_name'] ?></a></td>
					    	<td><a href="<?php echo $rowPost['post_url']; ?>" target="_blank"><?php echo $trimUrl ?></a>
					    		<div class="row social-stats text-muted" data-url="<?php echo base64_encode($rowPost['post_url']) ?>">
					    			<div class="col-md-4 like" title="Like count"><span class="glyphicon glyphicon-thumbs-up"> </span></div>
					    			<div class="col-md-4 comment" title="Comment count"><span class="glyphicon glyphicon-comment"> </span></div>
					    			<div class="col-md-4 share" title="Share count"><span class="glyphicon glyphicon-share"> </span></div>

					    		</div>
					    	</td>
					    	<td><?php echo $rowPost['post_name'] ?></td>
					    	<td><?php echo $rowPost['post_message'] ?></td>
					    	<td><?php echo $glyphicon; ?> <?php echo date(TIME_FORMAT, $publishTime) ?></td>
					    </tr>
					    <?php
						    }
					    ?>
					  </table>
					</div>
					<?php if($pages->num_pages > 1): ?>
					<div class="pull-right">
						<ul class="pagination pagination-sm" style="margin: 0;">
							<?php echo $pages->display_pages() ?>
						</ul>
					</div>
					<?php endif; ?>
					<?php }else{ ?>
					<div class="alert alert-warning">
			    		You don't have any post yet. To add new post, use the form on the right.
			    	</div>
					<?php } ?>
				</div>
				<?php if(!empty($arrPublished)): ?>
				<script type="text/javascript">
				var queryString = '<?php echo $str = $page > 1 ? '?page=' . $page . '&' : '?' ?>';
				var pageId = '<?php echo $pageId ?>';
				$(document).ready(function(){
					$('#filter-page').val(pageId);

					var urls = '<?php echo json_encode($arrPublished); ?>';
					$.ajax({
						url: '<?php echo route('ajax') ?>',
						dataType: 'json',
						type: 'POST',
						data: {urls:urls,'act':'fbstat'},
						success: function(rs){
							if(rs != null && typeof rs != 'undefined' && typeof rs.error == 'undefined'){
								for(var key in rs){
									$("div[data-url='" + key + "'] div.like").append(' ' + rs[key].like_count);
									$("div[data-url='" + key + "'] div.comment").append(' ' + rs[key].comment_count);
									$("div[data-url='" + key + "'] div.share").append(' ' + rs[key].share_count);
								}
							}
							else{
								console.log('Error when getting data');
							}
						}
					});
					$("#filter-page").change(function(){
						var pageId = $(this).val();
						if(pageId != ''){
							location.href = queryString + 'pageid=' + pageId;
						}
						else{
							location.href = '<?php echo route('page') ?>';
						}
					});
				});
				</script>
				<?php endif; ?>